package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.bean.PatrolPic;

import java.util.ArrayList;


public class PatrolPicDetailActivity extends Activity {


    private int position = 0;
    private ArrayList<PatrolPic> picBeenList;
    private ImageView iv_pic;
    private RelativeLayout rl_back;
    private LinearLayout ll_up;
    private LinearLayout ll_next;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patrol_info_pic_detail);
        iv_pic = findViewById(R.id.iv_pic);
        rl_back = findViewById(R.id.rl_back);
        rl_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ll_up = findViewById(R.id.ll_up);
        ll_up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (position == 0) {
                    Toast.makeText(PatrolPicDetailActivity.this, "当前为第一张", Toast.LENGTH_SHORT).show();
                } else {
                    position--;
                    Glide.with(PatrolPicDetailActivity.this)
                            .load(picBeenList.get(position).getAttach_url())
                            .error(R.drawable.loading).placeholder(R.drawable.loading)
                            .into(iv_pic);
                }

            }
        });
        ll_next = findViewById(R.id.ll_next);
        ll_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (position == picBeenList.size() - 1) {
                    Toast.makeText(PatrolPicDetailActivity.this, "当前为最后一张", Toast.LENGTH_SHORT).show();
                } else {
                    position++;
                    Glide.with(PatrolPicDetailActivity.this)
                            .load(picBeenList.get(position).getAttach_url())
                            .error(R.drawable.loading).placeholder(R.drawable.loading)
                            .into(iv_pic);
                }
            }
        });
        position = getIntent().getIntExtra("position", 0);
        picBeenList = (ArrayList<PatrolPic>) getIntent().getSerializableExtra("list");
        Glide.with(PatrolPicDetailActivity.this)
                .load(picBeenList.get(position).getAttach_url())
                .error(R.drawable.loading).placeholder(R.drawable.loading)
                .into(iv_pic);
    }
}
